import lzRequest from '../index'

import { IAccount, ILoginResult } from './type'
import { IDataType } from '../types'

enum LoginAPI {
  AccountLogin = '/user/login',
  LoginUserInfo = 'user/get_user_info/', // 用法: /user/1
  UserMenus = 'user/get_user_menu_by_role_id' // 用法: role/1/menu
}

export function accountLoginRequest(account: IAccount) {
  return lzRequest.post<IDataType<ILoginResult>>({
    url: LoginAPI.AccountLogin,
    data: account
  })
}

export function requestUserInfoById(id: number) {
  return lzRequest.get<IDataType>({
    url: LoginAPI.LoginUserInfo + id,
    showLoading: false
  })
}

export function requestUserMenusByRoleId(id: string) {
  // console.log('2222222222')
  // console.log(LoginAPI.UserMenus + 'menu')
  return lzRequest.post<IDataType>({
    url: LoginAPI.UserMenus,
    data: { role_id: id },
    showLoading: false
  })
}
